<include file="public@header" xmlns="http://www.w3.org/1999/html"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:url('Homework/index')}">作业列表</a></li>
    </ul>
    <form class="well form-inline margin-top-20 row" method="post" action="{:url('Homework/index')}">
        <label for="开始时间" class="col-md-6 col-xs-12 form-group">
            开始时间:
            <input class="form-control" type="text" name="homework_starttime" style="" value="{:input('request.homework_starttime')}"
                   placeholder="年/月/日">
            -
            <input class="form-control" type="text" name="homework_endtime" style="" value="{:input('request.homework_endtime')}"
                   placeholder="年/月/日">
        </label>
        <label for="选择班级" class="col-md-4 col-xs-6 form-group">
            选择班级:
                <select class="form-control"  name="class" class="class_id">
                    <option value="">选择班级</option>
                    <if condition="$role_id!=4">  <!-- TODO:JDIFJ -->
                        <foreach name="class_all" item="vo">
                            <if condition="isset($param.class) && $param.class == $vo.id ">
                                <option value="{$vo.id}" selected>
                                    {$vo.name}
                                </option>
                                <else/>
                                <option value="{$vo.id}">
                                    {$vo.name}
                                </option>
                            </if>
                        </foreach>
                        <else/>
                        <foreach name="class_all" item="vo">
                            <if condition="isset($param.class) && $param.class == $vo.id ">
                                <option value="{$vo.id}" selected>
                                    {$vo.name}
                                </option>
                                <else/>
                                <option value="{$vo.id}">
                                    {$vo.name}
                                </option>
                            </if>
                        </foreach>
                    </if>
                </select>
        </label>
        <label  for="选择老师" class="form-group col-xs-12 col-md-2">
            <if condition="$role_id==4">
                <else/>
                选择老师：
                <select name="select_teacher_id" class="form-control" id="select_teacher_id">
                    <option value="0" >选择老师</option>
                    <foreach name="all_teacher" item="vo">
                        <if condition="isset($param.select_teacher_id) && $param.select_teacher_id == $vo.id ">
                             <option value="{$vo.id}" selected>{$vo.user_login}</option>
                            <else/>
                             <option value="{$vo.id}" >{$vo.user_login}</option>
                        </if>
                    </foreach>
                </select>
            </if>
        </label>
        <label for="搜索" class="col-md-offset-10 col-md-2 col-xs-6 form-group" style="margin-top:15px; ">
            <input type="submit" class="btn btn-primary" value="搜索"/>
            <a class="btn btn-danger" href="{:url('Homework/index')}">清空</a>
        </label>
    </form>

        <form class="js-ajax-form" action="" method="post">
            <div class="table-actions" style="margin-top:20px;">

                    <button class="btn btn-danger btn-sm js-ajax-submit" type="submit"
                            data-action="{:url('Homework/delete')}" data-subcheck="true" data-msg="您确定删除吗?" >
                        批量删除
                    </button>
                    <a class="visit_add btn btn-sm btn-primary" >
                        添加
                    </a>
            </div>
            <table class="table table-hover table-bordered table-list">
                <thead>                                               <tr>
                    <th width="15">
                        <label>
                            <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                        </label>
                    </th>

                    <th width="">编号</th>
                    <th width="">班级</th>
                    <th width="">授课老师</th>
                    <th width="">课次</th>
                    <th width="">上课进度</th>
                    <th width="">作业内容</th>
                    <th width="">时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <foreach name="data" item="vo">
                    <tr>
                        <td>
                            <input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
                                   value="{$vo.id}" title="ID:{$vo.id}">
                        </td>
                        <td>{$vo.id}</td>
                        <td>{$vo.cname}</td>
                        <td>{$vo.user_login}</td>
                        <td>{$vo.progress}</td>
                        <td>{$vo.lesson_theme}</td>
                        <td>{$vo.content}</td>
                        <input type="hidden" id="teacher_id" value="{$vo.uid}">
                        <td>
                            {:date('Y-m-d H:i:s',$vo['create_time'])}
                        </td>
                        <td>
                            <a href="#" class="edit_visit" attr_id="{$vo.id}" class="js-ajax-edit">
                                编辑
                            </a>|
                            <a href="{:url('Homework/delete',array('id'=>$vo.id))}" class="js-ajax-delete">
                                删除
                            </a>
                        </td>
                    </tr>
                </foreach>
            </table>
            <div class="pagination">{$page}</div>
        </form>
    </div>

    <div id="visit_add_msg" >
        <form action="{:url('Homework/addPost')}" method="post" class="well row form-horizontal js-ajax-form" style="margin:0;">
            <label  class="form-group col-xs-12" for="">
                <if condition="$role_id==4">
                    <input type="hidden" name="teacher_id" id="put_tid" value="">
                    <else/>
                    选择老师：
                    <select name="teacher_id" class="form-control" id="teacher_id_id">
                        <option >选择老师</option>
                        <foreach name="all_teacher" item="vo">
                            <option value="{$vo.id}">{$vo.user_login}</option>
                        </foreach>
                    </select>
                </if>
            </label>
            <label class="form-group col-xs-12" for="">
                选择班级:
                    <select class="form-control class_id"  name="class_id"  id="class_id_id" >
                            <option value="">选择班级</option>
                            <if condition="$role_id!=4">

                                </foreach>
                                <else/>
                                <foreach name="class_all" item="vo">
                                    <if condition="isset($param.class) && $param.class == $vo.id ">
                                        <option value="{$vo.id}" selected>
                                            {$vo.name}
                                        </option>
                                        <else/>
                                        <option value="{$vo.id}">
                                            {$vo.name}
                                        </option>
                                    </if>
                                </foreach>
                            </if>

                        </select>
                    </select>
            </label>

            <label  class="form-group col-xs-12" for="">
                课次
                <input type="number"  class="form-control" id="progress"  name="progress"  placeholder="请输入当前课次" required="required">
            </label>

            <label  class="form-group col-xs-12" for="">
                上课进度
                <textarea class="form-control"  id="lesson_theme"  name="lesson_theme" cols="18" rows="4" required="required" placeholder="请输入课程的进度内容" required="required"></textarea>
                <!--<input type="text"  class="form-control" id="lesson_theme"  name="lesson_theme" cols="40" rows="10"  placeholder="请输入课程的内容" required="required">-->
            </label>
            <label  class="form-group col-xs-12" for="">
                作业内容:
                <textarea class="form-control"  name="content" cols="18" rows="4" required="required" placeholder="请输入作业内容" required="required"></textarea>
                <!--<script type="text/plain" id="content" name="content"></script>-->
            </label>
            <button type="submit" class="btn btn-primary js-ajax-submit" style="display: none">添加</button>
        </form>
    </div>

<div id="visit_edit_msg" style="display: none" >
    <form  action="{:url('Homework/editPost')}" method="post" class="well row form-horizontal js-ajax-form" style="margin:0;"><!--form-horizontal -->
        <label class="form-group col-xs-12" for="">
            <input type="hidden" id="id" name="id" value="">

            <if condition="empty($class_all)">
                <else/>
                选择班级:
                <select class="form-control class_id"  name="class_id" class="class_id" id="class_id">
                    <foreach name="class_all" item="vo1">
                        <option value="{$vo1.id}">
                            {$vo1.name}
                        </option>
                    </foreach>
                </select>
            </if>

        </label>
        <label  class="form-group col-xs-12" for="">
            课次
            <input type="number"  class="form-control" id="editprogress"  name="progress" placeholder="请输入当前课次" required="required">
        </label>
        <label  class="form-group col-xs-12" for="">
            课程进度:
            <textarea type="lesson_theme" cols="18" rows="4" class="form-control" id="progressedit"  name="lesson_theme"  placeholder="请输入课程的进度内容" required="required"></textarea>
        </label>
        <label  class="form-group col-xs-12" for="">
            作业内容:
            <!--<script type="text/plain" id="content1" name="content"></script>-->
            <textarea class="form-control" name="content" id="content1" cols="18" rows="4"></textarea>
        </label>
        <button type="submit" class="js-ajax-submit" id="js-ajax-submit1" style="display:none;"></button>
    </form>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script src="__STATIC__/js/layer/layer.js"></script>
<script type="text/javascript">
    //编辑器路径定义
    var editorURL = GV.WEB_ROOT;
</script>
<!--chase注释:此处用textarea就可,另时间选择插件已在header里加载,如若不需要精确到选择时分,不用加载timepicker

<!--<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>-->
<!--<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>-->
<!-- 时间选择的插件 -->
<!--<script type="text/javascript" src="__STATIC__/js/jquery-ui/jquery-ui-timepicker-addon.min.js"></script>-->
    <script>
        $(function(){
            //add
            $('body').on('click','.visit_add',function () {
                $("#put_tid").val($("#teacher_id").val());
                layer.open({
                    type: 1,
                    btn: ['添加'],
//                    area: ['700px', '400px'],
                    title: '添加课程作业',
                    content: $('#visit_add_msg'),
                    yes: function (index, layero) {
                        $('#visit_add_msg form button').click();
                    }
                })
            })

            $('[name="homework_starttime"]').datepicker();
            $('[name="homework_endtime"]').datepicker();
            $('#homework_starttime').datepicker();
            $('#homework_endtime').datepicker();



            $('body').on('click','.edit_visit',function ()
            {

                $id=$(this).attr('attr_id');
                $.ajax({
                    'url':"{:url('Homework/edit')}",
                    'data':{'id':$id},
                    'success':function(data)
                    {
                        data=jQuery.parseJSON(data);
                        var count=$("#class_id option").length;
                        for(var i=0;i<count;i++){
                            if($("#class_id").get(0).options[i].value==data.class_id)
                            {
                                $("#class_id").get(0).options[i].selected=true;
                            }
                        }
                        $("#id").val($id);
                        $("#progressedit").val(data['lesson_theme']);
                        $("#content1").val(data.content);
                        $("#editprogress").val(data.progress);

                    },
                })
                layer.open({
                    type: 1,
                    btn: ['保存'],
//                    area: ['700px', '400px'],
                    title: '编辑课程作业',
                    content: $('#visit_edit_msg'),
                    yes: function (index,layero) {
                        $('#visit_edit_msg form #js-ajax-submit1').click();
                    }
                })
            })

            $('body').on('change','.class_id',function () {
               $id=$(this).find('option:selected').val();
                $_this=$(this);
                $.ajax({
                    'url':"{:url('Homework/changProgress')}",
                    'data':{'id':$id},
                    'success':function(data)
                    {
                        data=jQuery.parseJSON(data);
                         $("#progress").val(data.progress);
                        $("#progressedit").val(data.progress);
                    },
                    'error':function()
                    {
                    }

                })
            })

            $('body').on('change','#teacher_id_id',function () {
                $id=$(this).find('option:selected').val();
                $.ajax({
                    'url':"{:url('Homework/changeLesson')}",
                    'data':{'id':$id},
                    'success':function(data)
                    {
                        data=jQuery.parseJSON(data);
                        console.log(data);
                        $("#class_id_id").empty();
                        $("<option>选择班级</optioin>").appendTo($("#class_id_id"));
                        for(var i=0;i<data.length;i++)
                        {
                            $("<option value='"+data[i].id+"'>"+data[i].name+"</optioin>").appendTo($("#class_id_id"));
                        }
                    },
                    'error':function()
                    {
                    }

                })
            })

        })

    </script>
    </body>
    </html>


